<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
%>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="copyright" content="Tencent"/>
    <meta name="keywords" content=""/>
    <meta name="description" content=""/>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="format-detection" content="telephone=no">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0,user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <title>我的优惠券</title>
    <link rel="stylesheet" type="text/css" href="<%=path%>/css/marketing/mobile_coupon_public.css" />
    <link rel="stylesheet" type="text/css" href="<%=path%>/css/marketing/mobileCouponDetail.css" />
    <style>
  
    </style>
</head>
<body class="s_body">
    <div class="k_title">
        <h3 id="couponName"></h3>
        <img id="shapeCode" src="<%=path%>/images/marketing/txm.png" class="k_txm" /><br/>
        <div id="qrCode" class="k_txm"></div>
        <p id="couponCode">券码：</p>
    </div>
    <div class="s_box">
        <h4>使用条件</h4>
        <ul id="useRule">
        </ul>
    </div>
    <div class="s_box">
        <h4>详细说明</h4>
        <ul id="useDetail">
        </ul>
    </div>
    <!-- <div class="s_box">
        <ul>
           <li>
                                     参与门店：上海沙龙、肯德基亦庄、肯德基大兴、肯德基通州、上海沙龙、肯德基亦庄、肯德基大兴、肯德基通州
           </li>
        </ul>
    </div> -->
    <p class="s_btn" onclick="javascript:history.back(-1)">返回</p>

 
	<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
	<script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
	<script src="<%=path%>/js/marketing/public.js"></script>
	<script src="http://pv.sohu.com/cityjson?ie=utf-8"></script>
	<script src="http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jsbarcode/3.8.0/barcodes/JsBarcode.codabar.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.qrcode/1.0/jquery.qrcode.min.js"></script>
    <script type="text/javascript">
        var tenant_id="";
        var code="";
        $(function(){
        	init();
        })
        
        function init(){
        	tenant_id=getQueryString("tenant_id");
        	code=getQueryString("code");
        	getCouponDetail();
        }
        
        function getCouponDetail(){
        	var url="<%=path%>/api/coupon/queryDetailByCode";
			$.post(url, {
				"tenant_id" : tenant_id,
				"coupon_code" : code,
			}, function(data) {
				if(data.error_code==0){
					setHtml(data.data);
				}else{
					
				}
			});
        }
        
        function setHtml(data){
        	var couponCode=data.couponCode;
        	var couponName=data.couponName;
        	couponCode=couponCode.substring(2,couponCode.length)
        	if(StringEmpty(couponName)){
        		$('#couponName').html(couponName);
        	}
        	if(StringEmpty(couponCode)){
        		$('#couponCode').html("券码："+couponCode);
        		try {
        			$("#shapeCode").JsBarcode(couponCode+"");
        			
        			JsBarcode("#shapeCode", couponCode, {
        				 width:3,//设置条之间的宽度
        				 height:100,//高度
        				 displayValue:false//是否在条形码下方显示文字
/*         				 text:"456",//覆盖显示的文本
        				 fontOptions:"bold italic",//使文字加粗体或变斜体
        				 font:"fantasy",//设置文本的字体
        				 textAlign:"left",//设置文本的水平对齐方式
        				 textPosition:"top",//设置文本的垂直位置
        				 textMargin:5,//设置条形码和文本之间的间距
        				 fontSize:15,//设置文本的大小
        				 background:"#eee",//设置条形码的背景
        				 lineColor:"#2196f3",//设置条和文本的颜色。
        				 margin:15//设置条形码周围的空白边距 */
        				});
        			
        		}catch(err){
        			console.log(err);
        		}
        		//jQuery('#qrCode').qrcode(couponCode);
        		var qrcode=$('#qrCode').qrcode({
                    render: "canvas",
                    width: 100,
                    height:100,
                    text: couponCode
                });
        	}
        	var useRuleHtml="";
        	var sNum=1;
        	if(data.validityPeriodType==0){
				if(StringEmpty(data.startTime)){
					useRuleHtml+='<li>1.有效期限：'+data.startTime+'—'+data.expireTime+'</li>';
				}else{
					useRuleHtml+='<li>1.有效期限：'+data.expireTime+'</li>';
				}
				sNum++;
			}else{
				if(StringEmpty(data.createTime)){
					useRuleHtml+='<li>1.有效期限：'+data.createTime+'—'+data.expireTime+'</li>';
				}else{
					useRuleHtml+='<li>1.有效期限：'+data.expireTime+'</li>';
				}
				sNum++;
				
			}
        	//使用时段
        	if(StringEmpty(data.period_time_week)||StringEmpty(data.period_time_hour)){
        		useRuleHtml+="<li>使用时段：'+sNum+'.'+data.period_time_week+' '+data.period_time_hour+'</li>";
			}
        	//满减规则
        	if(data.limit_price>0){
        		useRuleHtml+='<li>'+sNum+'.满减规则：满'+data.limit_price/100+'</li>';
        	}
        	$('#useRule').html(useRuleHtml);
        	//详细说明
        	if(StringEmpty(data.useDescribe)){
        		var useDetailHtml="";
        		useDetailHtml+="<li>"+data.useDescribe+"</li>";
        		$('#useDetail').html(useDetailHtml);
        	}
        }
    </script>
    
</body>
</html>